package com.example.service.rabbit;


import java.util.Objects;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * @author eatfi
 */
@Slf4j
@Service
public class MyRabbitListener {
    @RabbitListener(queues = "test.queue")
    public void receive(String message) {
        System.out.println("Received Message: " + message);
    }

    @RabbitListener(queues = "direct.queue1")
    public void receiveFromDirectExchange(String message) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        SendMsgVO value = objectMapper.readValue(message, SendMsgVO.class);
        value = null;
        Objects.requireNonNull(value);
        log.info("deserialize msg: value.message={}, value.number={}", value.getMessage(), value.getNumber());
    }
}
